package com.cooldatasoft.domain.daoImpl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.cooldatasoft.domain.dao.DocumentDao;
import com.cooldatasoft.domain.model.Document;
import com.cooldatasoft.domain.model.DocumentType;
import com.cooldatasoft.domain.model.Project;

public class DocumentDaoImpl extends GenericDaoImpl<Document, Long> implements DocumentDao {

	@SuppressWarnings("unchecked")
	@Override
	public Document getByProjectAndType(Project project, DocumentType type) {
		Criteria reservationCrit = getSession().createCriteria(Document.class);
		reservationCrit.add(Restrictions.eq("project", project));
		reservationCrit.add(Restrictions.eq("type", type));
		
		List<Document> res = reservationCrit.list();
		return (res.size() > 0) ? res.get(0) : null;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Document> getByProject(Project project) {
		Criteria reservationCrit = getSession().createCriteria(Document.class);
		reservationCrit.add(Restrictions.eq("project", project));
		
		List<Document> res = reservationCrit.list();
		return ((res.size() > 0) ? res : new ArrayList<Document>());
	}
}
